<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/25/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/25/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/15/%E8%BD%AC%E8%BD%BD-stm32%20spi%20nss%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E4%BA%86%E8%A7%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/15/%E8%BD%AC%E8%BD%BD-stm32%20spi%20nss%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E4%BA%86%E8%A7%A3/" class="post-title-link" itemprop="url">转载-stm32 spi nss一篇文章带你了解</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-15 18:42:02" itemprop="dateCreated datePublished" datetime="2021-04-15T18:42:02+08:00">2021-04-15</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/15/%E8%BD%AC%E8%BD%BD-stm32%20spi%20nss%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E4%BA%86%E8%A7%A3/" class="post-meta-item leancloud_visitors" data-flag-title="转载-stm32 spi nss一篇文章带你了解" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/15/%E8%BD%AC%E8%BD%BD-stm32%20spi%20nss%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E4%BA%86%E8%A7%A3/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/15/%E8%BD%AC%E8%BD%BD-stm32%20spi%20nss%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E4%BA%86%E8%A7%A3/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    原文来源于csdn上的一篇文章，地址为：<a target="_blank" rel="noopener" href="https://blog.csdn.net/jackailson/article/details/109395447">https://blog.csdn.net/jackailson/article/details/109395447</a></p>
<h2 id="1-概述"><a href="#1-概述" class="headerlink" title="1. 概述"></a>1. 概述</h2><p>​    目前网络上使用stm32 spi的nss，基本上都使用的是nss的软件管理模式。对于nss的硬件管理模式，程序的配置以及对nss的软件管理模式与硬件管理模式的说明，真的少之又少。这可能跟stm32官方文档对nss的描述不清也有很大关系吧，下面就带大家理解理解nss，当然了这篇文章是笔者阅读了stm32 spi官方文档再结合网友的一些文章，最终以自己个人对nss理解来编写的，如果有错误之处，还请指正。</p>
<h2 id="2-nss的管理模式"><a href="#2-nss的管理模式" class="headerlink" title="2. nss的管理模式"></a>2. nss的管理模式</h2><p>​    nss的管理模式分为：硬件管理和软件管理。nss的管理模式由SSM决定。</p>
<p>​    nss其实分为外部引脚和内部引脚的。外部nss引脚就是芯片上肉眼可见的与GPIO复用的引脚；内部nss引脚就是stm32芯片里集成的spi模块引脚，肉眼不可见。换句话说，真正与spi通信控制器连接的是内部nss引脚，外部nss引脚不能直接连到芯片内部的spi模块，而是先连接内部nss引脚，通过内部nss引脚作用spi模块。</p>
<h2 id="3-nss的管理模式配置"><a href="#3-nss的管理模式配置" class="headerlink" title="3. nss的管理模式配置"></a>3. <strong>nss的管理模式配置</strong></h2><p>​    SSM在SPI_CR1控制器里，默认为0。</p>
<p>​    SSM可以控制内部nss引脚与SSI（一个寄存器，软件模式）相连，还是与外部nss引脚（真正的STM32引脚，硬件模式）相连。真正起作用的是内部nss引脚（内部nss引脚才真正连接到SPI通信控制器上）。</p>
<p>​    当SSM=0：说明使用硬件管理模式，内部nss引脚与外部nss引脚相连，忽视SSI位，对SPI_CR1的SSI位的写操作无效；</p>
<p>​    当SSM=1：说明使用软件管理模式，内部nss引脚与SSI相连，忽视外部nss引脚，我们可以把外部nss引脚当做普通IO口；</p>
<h2 id="4-spi从模式配置-MSTR-0"><a href="#4-spi从模式配置-MSTR-0" class="headerlink" title="4. spi从模式配置(MSTR=0)"></a>4. <strong>spi从模式配置(MSTR=0)</strong></h2><p>​    (1).nss硬件模式(SSM=0)</p>
<p>​    当外部nss引脚为低电平时，内部nss也为低电平，相当于片选该从器件，此时spi可以传输数据。外部nss引脚需要配置为复用功能。</p>
<p>​    (2).nss软件模式(SSM=1)</p>
<p>​    SSM=1并且SSI=0，STM32芯片让内部nss引脚为低电平，相当于片选该从器件，此时spi可以传送数据。外部nss引脚被释放，可做普通IO作为其他用途使用。</p>
<h2 id="5-spi主模式配置-MSTR-1"><a href="#5-spi主模式配置-MSTR-1" class="headerlink" title="5. spi主模式配置(MSTR=1)"></a>5. <strong>spi主模式配置(MSTR=1)</strong></h2><p>(1).nss硬件模式(SSM=0)</p>
<p>​    在spi主模式下，nss硬件模式又分为输入模式和输出模式，由SSOE位决定。</p>
<p>​    a.输入模式(SSOE=0)：在外部nss引脚为高电平，内部nss引脚也为高电平，此时才能进行数据传输。如果要使能从设备，还需要一个GPIO引脚。</p>
<p>​    在此情况下，外部nss要是被接低电平，则会进入主模式故障，MSTR会清零，由主模式进入从模式。</p>
<p>​    外部nss引脚需要配置为复用功能，并且外部nss引脚必须接入一个高电平，它才能维持主模式状态。stm32官方手册spi章节有说明，也就一句话，如果你不注意，可能就无法发现，如下图：<br><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20201030232010403.png" style="zoom:67%;"></p>
<p>​    b.输出模式(SSOE=1):当使能spi模块时，外部nss引脚会被芯片自动输出低电平，使能从设备，进行数据传输，不需要额外的GPIO引脚就能片选从设备（输出模式时，貌似不需要遵循上图框出来的内容，那段话可能就是针对输入模式写的，输出模式是spi模块控制内部nss引脚，因此也就不必遵循那段话）。</p>
<p>​    外部NSS引脚需要配置为复用功能，再把此引脚连接到从器件的CS引脚，因此外部NSS引脚就相当于片选引脚了。</p>
<p>​    (2).nss软件模式(SSM=1)</p>
<p>​    SSM=1，并且SSI=1，将内部nss引脚设置为高电平，<strong>这样随时可以传输数据</strong>（这句话遵循上图框出来的内容）。<strong>当然多数情况还需要一个GPIO引脚输出低电平，来使能从设备，让从设备可以接收数据</strong>。</p>
<p>​    综上所述，nss引脚就是片选CS引脚是很不负责任的说法。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/15/MM32F103CBT6%20USB%E4%BE%8B%E7%A8%8B%E6%97%B6%E9%92%9F%E4%BF%AE%E6%94%B9/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/15/MM32F103CBT6%20USB%E4%BE%8B%E7%A8%8B%E6%97%B6%E9%92%9F%E4%BF%AE%E6%94%B9/" class="post-title-link" itemprop="url">MM32F103CBT6 USB例程时钟修改</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-15 11:15:46" itemprop="dateCreated datePublished" datetime="2021-04-15T11:15:46+08:00">2021-04-15</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/15/MM32F103CBT6%20USB%E4%BE%8B%E7%A8%8B%E6%97%B6%E9%92%9F%E4%BF%AE%E6%94%B9/" class="post-meta-item leancloud_visitors" data-flag-title="MM32F103CBT6 USB例程时钟修改" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/15/MM32F103CBT6%20USB%E4%BE%8B%E7%A8%8B%E6%97%B6%E9%92%9F%E4%BF%AE%E6%94%B9/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/15/MM32F103CBT6%20USB%E4%BE%8B%E7%A8%8B%E6%97%B6%E9%92%9F%E4%BF%AE%E6%94%B9/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    最近在调试灵动微MM32F103CBT6的USB，官方提供了USB的demo例子。它的例子是可以跑通的，但是存在一个问题，由于USB工作需要使用48MHz的时钟，demo例子中是直接把PLL时钟设置成了48MHz，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415104122.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415104555.png" style="zoom:67%;">

<p>demo程序把PLLCLK直接配置成了48MHZ，usb prescaler没进行分频，这样usb时钟也就是48MHz，但是这样就不能把mcu主频跑到它的96MHz了,需要进行修改。</p>
<h2 id="1-修改时钟选择"><a href="#1-修改时钟选择" class="headerlink" title="1. 修改时钟选择"></a>1. 修改时钟选择</h2><p>​    有三种不同的时钟源可被用来驱动系统时钟 (SYSCLK):</p>
<p>​    •HSI振荡器时钟</p>
<p>​    •HSE振荡器时钟</p>
<p>​    •PLL时钟</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415105708.png" style="zoom:67%;">

<p>官方demo默认用的是SYSCLK_HSI_96MHz(其实demo后面调用了SetUSBSysClockTo48M函数，把之前的时钟配置覆盖了)，我们这边把它改成使用SYSCLK_FREQ_96MHz，即使用PLL产生的时钟。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">SetSysClockTo96</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> i = <span class="number">100000</span>;</span><br><span class="line">    __IO <span class="keyword">uint32_t</span> StartUpCounter = <span class="number">0</span>, HSEStatus = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> nTime = <span class="number">2</span>;</span><br><span class="line">    <span class="comment">/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/</span></span><br><span class="line">    <span class="comment">/* Enable HSE */</span></span><br><span class="line">    RCC-&gt;CR |= ((<span class="keyword">uint32_t</span>)RCC_CR_HSEON);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* Wait till HSE is ready and if Time out is reached exit */</span></span><br><span class="line">    <span class="keyword">do</span></span><br><span class="line">    &#123;</span><br><span class="line">        HSEStatus = RCC-&gt;CR &amp; RCC_CR_HSERDY;</span><br><span class="line">        StartUpCounter++;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span>((HSEStatus == <span class="number">0</span>) &amp;&amp; (StartUpCounter != HSE_STARTUP_TIMEOUT));</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*delay more than 2ms*/</span></span><br><span class="line">    <span class="keyword">while</span>(nTime--)</span><br><span class="line">    &#123;</span><br><span class="line">        i = <span class="number">1500</span>;</span><br><span class="line">        <span class="keyword">while</span>(i--);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> ((RCC-&gt;CR &amp; RCC_CR_HSERDY) != RESET)</span><br><span class="line">    &#123;</span><br><span class="line">        HSEStatus = (<span class="keyword">uint32_t</span>)<span class="number">0x01</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        HSEStatus = (<span class="keyword">uint32_t</span>)<span class="number">0x00</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    i = <span class="number">10000</span>; <span class="keyword">while</span>(i--);</span><br><span class="line">    <span class="keyword">if</span> (HSEStatus == (<span class="keyword">uint32_t</span>)<span class="number">0x01</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/* Enable Prefetch Buffer */</span></span><br><span class="line">        FLASH-&gt;ACR |= FLASH_ACR_PRFTBE;</span><br><span class="line">        <span class="comment">/* Flash 0 wait state ,bit0~2*/</span></span><br><span class="line">        FLASH-&gt;ACR &amp;= ~<span class="number">0x07</span>;</span><br><span class="line">        FLASH-&gt;ACR |= <span class="number">0x03</span>;</span><br><span class="line">        <span class="comment">/* HCLK = SYSCLK */</span></span><br><span class="line">        RCC-&gt;CFGR |= (<span class="keyword">uint32_t</span>)RCC_CFGR_HPRE_DIV1;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* PCLK2 = HCLK */</span></span><br><span class="line">        RCC-&gt;CFGR |= (<span class="keyword">uint32_t</span>)RCC_CFGR_PPRE2_DIV1;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* PCLK1 = HCLK */</span></span><br><span class="line">        RCC-&gt;CFGR |= (<span class="keyword">uint32_t</span>)RCC_CFGR_PPRE1_DIV2;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/*  PLL configuration:  = (HSE ) * (11+1) = 96 MHz */</span></span><br><span class="line">        RCC-&gt;CFGR &amp;= (<span class="keyword">uint32_t</span>)<span class="number">0xFFFCFFFF</span>;</span><br><span class="line">        RCC-&gt;CR &amp;= (<span class="keyword">uint32_t</span>)<span class="number">0x000FFFFF</span>;</span><br><span class="line"></span><br><span class="line">        RCC-&gt;CFGR |= (<span class="keyword">uint32_t</span>)RCC_CFGR_PLLSRC ;</span><br><span class="line">        RCC-&gt;CR |= <span class="number">0x2C000000</span>;<span class="comment">//pll = 12/1</span></span><br><span class="line">        <span class="comment">//RCC-&gt;CFGR &amp;= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));</span></span><br><span class="line">        <span class="comment">//RCC-&gt;CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6);</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/* Enable PLL */</span></span><br><span class="line">        RCC-&gt;CR |= RCC_CR_PLLON;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* Wait till PLL is ready */</span></span><br><span class="line">        <span class="keyword">while</span>((RCC-&gt;CR &amp; RCC_CR_PLLRDY) == <span class="number">0</span>)</span><br><span class="line">        &#123;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* Select PLL as system clock source */</span></span><br><span class="line">        RCC-&gt;CFGR &amp;= (<span class="keyword">uint32_t</span>)((<span class="keyword">uint32_t</span>)~(RCC_CFGR_SW));</span><br><span class="line">        RCC-&gt;CFGR |= (<span class="keyword">uint32_t</span>)RCC_CFGR_SW_PLL;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* Wait till PLL is used as system clock source */</span></span><br><span class="line">        <span class="keyword">while</span> ((RCC-&gt;CFGR &amp; (<span class="keyword">uint32_t</span>)RCC_CFGR_SWS) != (<span class="keyword">uint32_t</span>)<span class="number">0x08</span>)</span><br><span class="line">        &#123;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/* If HSE fails to start-up, the application will have wrong clock</span></span><br><span class="line"><span class="comment">          configuration. User can add here some code to deal with this error */</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>代码中可以看到：*<em>/</em>  PLL configuration:  = (HSE ) * (11+1) = 96 MHz */**</p>
<h2 id="2-USB分频"><a href="#2-USB分频" class="headerlink" title="2. USB分频"></a>2. USB分频</h2><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415110403.png" style="zoom:57%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415110507.png" style="zoom:67%;">

<p>添加代码如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415110707.png" style="zoom:70%;">

<p>这个函数会在SystemInit中被调用，原来SetUSBSysClockTo48M函数不用调用即可：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210415111138.png" style="zoom:67%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/11/%E6%9C%BA%E6%A2%B0%E6%8C%AF%E5%8A%A8FFT%E9%A2%91%E8%B0%B1%E5%88%86%E6%9E%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/11/%E6%9C%BA%E6%A2%B0%E6%8C%AF%E5%8A%A8FFT%E9%A2%91%E8%B0%B1%E5%88%86%E6%9E%90/" class="post-title-link" itemprop="url">机械振动FFT频谱分析</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-11 14:54:00" itemprop="dateCreated datePublished" datetime="2021-04-11T14:54:00+08:00">2021-04-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2021/04/11/%E6%9C%BA%E6%A2%B0%E6%8C%AF%E5%8A%A8FFT%E9%A2%91%E8%B0%B1%E5%88%86%E6%9E%90/" class="post-meta-item leancloud_visitors" data-flag-title="机械振动FFT频谱分析" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/11/%E6%9C%BA%E6%A2%B0%E6%8C%AF%E5%8A%A8FFT%E9%A2%91%E8%B0%B1%E5%88%86%E6%9E%90/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/11/%E6%9C%BA%E6%A2%B0%E6%8C%AF%E5%8A%A8FFT%E9%A2%91%E8%B0%B1%E5%88%86%E6%9E%90/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    这个好像是玻利维亚的一个人做的项目，在github上，仓库地址为：github.com/ariquezada/FFT-spectrum-analyzer。</p>
<h2 id="1-概述"><a href="#1-概述" class="headerlink" title="1. 概述"></a>1. 概述</h2><p>​    机械振动通常是总体机械状态的最佳指标，用于预防性和矫正性维修。可以使用加速度计来测量，可以得到一个指示振动最大值的整体读数，但是通常最有用的信息是用一个时间周期读数的FFT频谱分析来获得。</p>
<h2 id="2-ADXL335"><a href="#2-ADXL335" class="headerlink" title="2. ADXL335"></a>2. ADXL335</h2><h3 id="2-1-芯片简介"><a href="#2-1-芯片简介" class="headerlink" title="2.1 芯片简介"></a>2.1 芯片简介</h3><p>​    项目使用的是ADXL335三轴加速度传感器，下面简单介绍一下该芯片。ADXL335提供经过信号调理的电压输出，满量程加速度测量范围为±3 g，灵敏度为300±10%mV/g。它可以测量倾斜检测应用中的静态重力加速度，以及运动、冲击或振动导致的动态加速度。用户使用CX、CY 和CZ 引脚上的电容XOUT、YOUT 和ZOUT 选择该加速度计的带宽。可以根据应用选择合适的带宽，X 轴和Y 轴的带宽范围为0.5 Hz 至1600 Hz，Z 轴的带宽范围为0.5 Hz 至550 Hz。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210407153959.png" style="zoom:70%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210407154850.png" style="zoom:77%;">

<h3 id="2-2-带宽参数的理解"><a href="#2-2-带宽参数的理解" class="headerlink" title="2.2 带宽参数的理解"></a>2.2 带宽参数的理解</h3><p>​    关于带宽的理解以及下面提到的设置依据，参考了网友的博客，原文地址为：<a target="_blank" rel="noopener" href="https://www.jianshu.com/p/772741e0b8a8">https://www.jianshu.com/p/772741e0b8a8</a> 。通俗的讲，加速度计的带宽是指能够测量到的信号的最大变化率，高于带宽的信号加速度计无法通过采样还原真实的信号变化。</p>
<p>​    将加速度计传感器静止放置，测量出来的值也会在平均值上下波动，为了降低噪声，加速度计内部通常会自带一个低通滤波器（LPF）来过滤高频分量，传感器的带宽就是指低通滤波器的带宽，高于带宽的信号变化将无法测量出来。</p>
<h3 id="2-3-带宽设置依据"><a href="#2-3-带宽设置依据" class="headerlink" title="2.3 带宽设置依据"></a>2.3 带宽设置依据</h3><p>​    直观的说，带宽设置越小，测量到的数据曲线越平滑，但信号变化会越滞后，对于高于带宽的信号变化无法测到。相反，带宽设置越大，数据曲线噪声越大，毛刺越多，但在测量数据变化的时候能够更加快速地响应其变化。</p>
<p>​    带宽的设置需根据实际测量的物体的实际变化快慢来定，在能够满足测量要求的情况下应尽量设置低的带宽，以获取更加平稳的测量数据，降低噪声，但需要高于需要测量的有效信号的变化频率。</p>
<p>​    网友是用维特智能JY61模块测量农机执行机构角度，农机的执行机构角度变化是非常缓慢的，提升或降低大约需要5-10秒时间，而实际测量到的角度中还包含了发动机带来的震动，振动频率相对较高，一般大于10Hz,这种情况下，可以将带宽设置到最低5Hz,这样可以有效过滤掉发动机抖动带来的高频振荡信号，获得更加平滑的有效测量值。</p>
<h2 id="3-做FFT频谱操作"><a href="#3-做FFT频谱操作" class="headerlink" title="3. 做FFT频谱操作"></a>3. 做FFT频谱操作</h2><p>​    实验的时候ADC在给定的采样频率（5000赫兹）上读取加速度计振动通道，为应用选择最大带宽，X和Y轴的范围为1600赫兹。Z轴的最大范围是550Hz，因此这个5000Hz的采样频率是可以的，因为采样频率大于信号最高频率的2倍，信号不会失真。</p>
<p>​    假设a是时域中的周期信号，采样频率为Fs，采样点数为N。如果A[N] = fft(a[N])，返回值A[N]是一个复数数组，其中：（原文链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/matthewwu/article/details/102621460%EF%BC%89">https://blog.csdn.net/matthewwu/article/details/102621460）</a></p>
<ul>
<li>A[0]表示频率为0hz的信号，即直流分量。</li>
<li>A[1:N/2]包含正频率项，A[N/2:]包含负频率项。正频率项就是转化后的频域信号，通常我们只需要正频率项，即前面的n/2项，负频率项是计算的中间结果（正频率项的镜像值）。</li>
<li>每一项的频率计算：假设A[i]为数组中的元素，表示一个波形，*<em>该波形的频率 = i * Fs / N*</em></li>
</ul>
<p><strong>频率分辨率概念：</strong><br>    频率分辨率是离散傅里叶变换(DFT)频域相邻刻度之间的实际频率之差。采样时，数据采样了T秒(T = 采样点数N / 采样频率Fs)，<strong>信号的成分中周期最大也就是T秒，最低频率即“基频”就等于1 / T，</strong>也就是Fs / N，这就是频率分辨率。基频 = Fs / N，各个谐波的频率就是 i * Fs / N，这个公式用于计算各个波形的频率。    </p>
<p><strong>执行的效果图：</strong></p>
<p>​    在原始仓库的基础上，把核心代码抽出来简化了一下工程，去除了一些其他的操作，比如打开文件夹选择某个文件来分析这些操作，直接对某一个文件中的数据做分析，仓库地址：<a target="_blank" rel="noopener" href="https://gitee.com/xudonglei/machinery-vibration-fft-spectrum%EF%BC%8C%E6%95%88%E6%9E%9C%E5%A6%82%E4%B8%8B%E5%9B%BE%E6%89%80%E7%A4%BA%EF%BC%9A">https://gitee.com/xudonglei/machinery-vibration-fft-spectrum，效果如下图所示：</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210411144616.png" style="zoom:67%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/09/MM32F103CBT6%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%B5%8B%E8%AF%95FFT/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/09/MM32F103CBT6%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%B5%8B%E8%AF%95FFT/" class="post-title-link" itemprop="url">MM32F103CBT6平台上测试FFT</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-09 16:52:08" itemprop="dateCreated datePublished" datetime="2021-04-09T16:52:08+08:00">2021-04-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/09/MM32F103CBT6%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%B5%8B%E8%AF%95FFT/" class="post-meta-item leancloud_visitors" data-flag-title="MM32F103CBT6平台上测试FFT" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/09/MM32F103CBT6%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%B5%8B%E8%AF%95FFT/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/09/MM32F103CBT6%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%B5%8B%E8%AF%95FFT/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    为了测试FFT，我们直接使用arm提供的dsp库来做FFT，DSP库是包含在CMSIS 软件包（Cortex Microcontroller Software Interface Standard）里面，所以下载DSP库也就是下载 CMSIS 软件包。到Keil的官网就可以下载<a target="_blank" rel="noopener" href="http://www.keil.com/dd2/Pack/">http://www.keil.com/dd2/Pack/</a> ：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210407135445.png" style="zoom:57%;">

<p>下载后直接安装即可，在下面的路径中可以看到lib库了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210407135846.png" style="zoom:60%;">

<p>l表示小端格式，b表示大端格式，f表示带FPU单元。</p>
<p>​    把下面的.h头文件和上面的arm_cortexM3l_math.lib库加入到自己的工程中即可：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210407142609.png" style="zoom:65%;">

<p>​    部分测试的代码：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210409164843.png" style="zoom:67%;">

<p>​    计算时间大概需要1.5ms左右。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信图片_20210409165130.jpg" style="zoom:40%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/" class="post-title-link" itemprop="url">STM32L475待机模式闹钟唤醒方式</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-09 09:13:29" itemprop="dateCreated datePublished" datetime="2021-04-09T09:13:29+08:00">2021-04-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/" class="post-meta-item leancloud_visitors" data-flag-title="STM32L475待机模式闹钟唤醒方式" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/09/STM32L475%E5%BE%85%E6%9C%BA%E6%A8%A1%E5%BC%8F%E9%97%B9%E9%92%9F%E5%94%A4%E9%86%92%E6%96%B9%E5%BC%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    STM32L475提供了6种低功耗模式，以达到不同层次的降低功耗的目的，这六种模式如下：</p>
<p>1）休眠模式。 </p>
<p>2）低功耗运行模式。</p>
<p>3）低功耗睡眠模式。</p>
<p>4）Stop0，Stop1 和 Stop2 模式。 </p>
<p>5）待机模式</p>
<p>6）关机模式</p>
<p>​    这边主要介绍待机模式，注意：在进入待机模式后，调试模式将不可用，我们也不能通过ST LINK下载程序到 MCU中。</p>
<p>​    设置方法如下：</p>
<p>​    1. 使用RTC的闹钟功能，就是alarm A/B功能。使用STM32cubemx配置RTC时选择 ALARM A，在RTC配置里面给alarm A的Alarm A中参数Minutes设置成你要的时间，当然也可以选择小时/秒等，具体根据需要。cubemx配置方法可以参考我之前的博文《<a target="_blank" rel="noopener" href="https://xudonglei.gitee.io/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/">STM32使用RTC时钟及闹钟功能</a>》</p>
<p>​    2.设置中断源为外部Exit int pin18，注意这个要设置，这个在之前博文中也设置了。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210408204947.png"></p>
<p>​    3.在main（）函数调用HAL_PWR_EnterSTANDBYMode()，就进入standby待机休眠状态，等待闹钟时间到就行了，到时会重新启动单片机。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210408210223.png" style="zoom:50%;">

<p>在正点原子的潘多拉开发板上做了测试，待机模式电流大约在42mA左右，还是比较大的，但是比正常运行模式的时候小一点，初步怀疑是因为板子上有其他元器件的缘故，后面空的时候会继续查找原因。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210408210641.jpg" style="zoom:20%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/" class="post-title-link" itemprop="url">CMSIS DSP库的复数定点FFT使用</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-08 18:55:36" itemprop="dateCreated datePublished" datetime="2021-04-08T18:55:36+08:00">2021-04-08</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/" class="post-meta-item leancloud_visitors" data-flag-title="CMSIS DSP库的复数定点FFT使用" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/08/CMSIS%20DSP%E5%BA%93%E7%9A%84%E5%A4%8D%E6%95%B0%E5%AE%9A%E7%82%B9FFT%E4%BD%BF%E7%94%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    CMSIS DSP库中定点复数FFT的输入需要使用Q31或者Q15的数，其中Q31的数它实际的范围是(-1, 1)。我先用python造了一些复数，做FFT；然后再在stm32上调用DSP库做FFT，并将两者结果对比。</p>
<p>​    直接上python代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    <span class="comment"># print(np.hamming(32))</span></span><br><span class="line">    <span class="comment"># x0 = np.random.random_sample((32,))</span></span><br><span class="line">    <span class="comment"># print(x0)</span></span><br><span class="line">    input_float = np.array([<span class="number">0.33688039</span>+<span class="number">0.27576947j</span>, <span class="number">0.99445967</span>+<span class="number">0.76294948j</span>,</span><br><span class="line">                            <span class="number">0.70402479</span>+<span class="number">0.07054292j</span>, <span class="number">0.44225181</span>+<span class="number">0.24120408j</span>,</span><br><span class="line">                            <span class="number">0.48560569</span>+<span class="number">0.12177725j</span>, <span class="number">0.18824296</span>+<span class="number">0.87400103j</span>,</span><br><span class="line">                            <span class="number">0.38203619</span>+<span class="number">0.13971502j</span>, <span class="number">0.21115924</span>+<span class="number">0.16845203j</span>,</span><br><span class="line">                            <span class="number">0.86836398</span>+<span class="number">0.44339537j</span>, <span class="number">0.91344222</span>+<span class="number">0.18359897j</span>,</span><br><span class="line">                            <span class="number">0.66934949</span>+<span class="number">0.953202j</span>,   <span class="number">0.98336128</span>+<span class="number">0.51880677j</span>,</span><br><span class="line">                            <span class="number">0.7314163</span>+<span class="number">0.41706149j</span>,  <span class="number">0.61245894</span>+<span class="number">0.02790013j</span>,</span><br><span class="line">                            <span class="number">0.20736128</span>+<span class="number">0.37723832j</span>, <span class="number">0.27917189</span>+<span class="number">0.33977751j</span>,</span><br><span class="line">                            <span class="number">0.79783386</span>+<span class="number">0.55812144j</span>, <span class="number">0.51681</span>+<span class="number">0.59290067j</span>,</span><br><span class="line">                            <span class="number">0.33205087</span>+<span class="number">0.87387007j</span>, <span class="number">0.19170072</span>+<span class="number">0.18220524j</span>,</span><br><span class="line">                            <span class="number">0.39737357</span>+<span class="number">0.69744759j</span>, <span class="number">0.28801394</span>+<span class="number">0.82422595j</span>,</span><br><span class="line">                            <span class="number">0.27648721</span>+<span class="number">0.49734381j</span>, <span class="number">0.63294795</span>+<span class="number">0.50805464j</span>,</span><br><span class="line">                            <span class="number">0.67525571</span>+<span class="number">0.15635329j</span>, <span class="number">0.44887195</span>+<span class="number">0.33571562j</span>,</span><br><span class="line">                            <span class="number">0.71634485</span>+<span class="number">0.82814263j</span>, <span class="number">0.49399417</span>+<span class="number">0.34142172j</span>,</span><br><span class="line">                            <span class="number">0.39951166</span>+<span class="number">0.56482186j</span>, <span class="number">0.51141589</span>+<span class="number">0.57559398j</span>,</span><br><span class="line">                            <span class="number">0.39054342</span>+<span class="number">0.41560708j</span>, <span class="number">0.65810208</span>+<span class="number">0.55645494j</span>])</span><br><span class="line">    fft_result = np.fft.fft(input_float * np.hamming(<span class="number">32</span>), <span class="number">32</span>)</span><br><span class="line">    print(fft_result)</span><br></pre></td></tr></table></figure>
<p>​    部分关键C代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Q15_ONE    (32768) </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Q16_ONE    (65536)   </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">float32_t</span> hamming_window[<span class="number">64</span>] =</span><br><span class="line">&#123;</span><br><span class="line">	<span class="number">0.08000000</span>, <span class="number">0.08000000</span>, <span class="number">0.08941623</span>, <span class="number">0.08941623</span>, <span class="number">0.11727941</span>, <span class="number">0.11727941</span>, <span class="number">0.16244882</span>, <span class="number">0.16244882</span>, </span><br><span class="line">	<span class="number">0.22307522</span>, <span class="number">0.22307522</span>, <span class="number">0.29667656</span>, <span class="number">0.29667656</span>, <span class="number">0.38023958</span>, <span class="number">0.38023958</span>, <span class="number">0.47034322</span>, <span class="number">0.47034322</span>, </span><br><span class="line">	<span class="number">0.56329862</span>, <span class="number">0.56329862</span>, <span class="number">0.65530016</span>, <span class="number">0.65530016</span>, <span class="number">0.74258131</span>, <span class="number">0.74258131</span>, <span class="number">0.82156875</span>, <span class="number">0.82156875</span>, </span><br><span class="line">	<span class="number">0.88902874</span>, <span class="number">0.88902874</span>, <span class="number">0.94219944</span>, <span class="number">0.94219944</span>, <span class="number">0.97890406</span>, <span class="number">0.97890406</span>, <span class="number">0.99763989</span>, <span class="number">0.99763989</span>, </span><br><span class="line">	<span class="number">0.99763989</span>, <span class="number">0.99763989</span>, <span class="number">0.97890406</span>, <span class="number">0.97890406</span>, <span class="number">0.94219944</span>, <span class="number">0.94219944</span>, <span class="number">0.88902874</span>, <span class="number">0.88902874</span>, </span><br><span class="line">	<span class="number">0.82156875</span>, <span class="number">0.82156875</span>, <span class="number">0.74258131</span>, <span class="number">0.74258131</span>, <span class="number">0.65530016</span>, <span class="number">0.65530016</span>, <span class="number">0.56329862</span>, <span class="number">0.56329862</span>, </span><br><span class="line">	<span class="number">0.47034322</span>, <span class="number">0.47034322</span>, <span class="number">0.38023958</span>, <span class="number">0.38023958</span>, <span class="number">0.29667656</span>, <span class="number">0.29667656</span>, <span class="number">0.22307522</span>, <span class="number">0.22307522</span>, </span><br><span class="line">	<span class="number">0.16244882</span>, <span class="number">0.16244882</span>, <span class="number">0.11727941</span>, <span class="number">0.11727941</span>, <span class="number">0.08941623</span>, <span class="number">0.08941623</span>, <span class="number">0.08000000</span>, <span class="number">0.08000000</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">uint16_t</span> hamming_window_Q16[<span class="number">64</span>];</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//实部,虚部,实部,虚部...</span></span><br><span class="line"><span class="keyword">float32_t</span> input_float[<span class="number">32</span>*<span class="number">2</span>] = </span><br><span class="line">&#123;</span><br><span class="line">     <span class="number">0.33688039</span>, <span class="number">0.27576947</span>, <span class="number">0.99445967</span>, <span class="number">0.76294948</span>,</span><br><span class="line">     <span class="number">0.70402479</span>, <span class="number">0.07054292</span>, <span class="number">0.44225181</span>, <span class="number">0.24120408</span>,</span><br><span class="line">     <span class="number">0.48560569</span>, <span class="number">0.12177725</span>, <span class="number">0.18824296</span>, <span class="number">0.87400103</span>,</span><br><span class="line">     <span class="number">0.38203619</span>, <span class="number">0.13971502</span>, <span class="number">0.21115924</span>, <span class="number">0.16845203</span>,</span><br><span class="line">     <span class="number">0.86836398</span>, <span class="number">0.44339537</span>, <span class="number">0.91344222</span>, <span class="number">0.18359897</span>,</span><br><span class="line">     <span class="number">0.66934949</span>, <span class="number">0.953202</span>,   <span class="number">0.98336128</span>, <span class="number">0.51880677</span>,</span><br><span class="line">     <span class="number">0.7314163</span>, <span class="number">0.41706149</span>,  <span class="number">0.61245894</span>, <span class="number">0.02790013</span>,</span><br><span class="line">     <span class="number">0.20736128</span>, <span class="number">0.37723832</span>, <span class="number">0.27917189</span>, <span class="number">0.33977751</span>,</span><br><span class="line">     <span class="number">0.79783386</span>, <span class="number">0.55812144</span>, <span class="number">0.51681</span>, <span class="number">0.59290067</span>,</span><br><span class="line">     <span class="number">0.33205087</span>, <span class="number">0.87387007</span>, <span class="number">0.19170072</span>, <span class="number">0.18220524</span>,</span><br><span class="line">     <span class="number">0.39737357</span>, <span class="number">0.69744759</span>, <span class="number">0.28801394</span>, <span class="number">0.82422595</span>,</span><br><span class="line">     <span class="number">0.27648721</span>, <span class="number">0.49734381</span>, <span class="number">0.63294795</span>, <span class="number">0.50805464</span>,</span><br><span class="line">     <span class="number">0.67525571</span>, <span class="number">0.15635329</span>, <span class="number">0.44887195</span>, <span class="number">0.33571562</span>,</span><br><span class="line">     <span class="number">0.71634485</span>, <span class="number">0.82814263</span>, <span class="number">0.49399417</span>, <span class="number">0.34142172</span>,</span><br><span class="line">     <span class="number">0.39951166</span>, <span class="number">0.56482186</span>, <span class="number">0.51141589</span>, <span class="number">0.57559398</span>,</span><br><span class="line">     <span class="number">0.39054342</span>, <span class="number">0.41560708</span>, <span class="number">0.65810208</span>, <span class="number">0.55645494</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">int16_t</span> input_Q15[<span class="number">32</span>*<span class="number">2</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int32_t</span> mul_Q31[<span class="number">64</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(i=<span class="number">0</span>; i&lt;<span class="number">64</span>; i++)</span><br><span class="line">&#123;</span><br><span class="line">	hamming_window_Q16[i] = round(hamming_window[i] * Q16_ONE);</span><br><span class="line">	input_Q15[i] = round(input_float[i] * Q15_ONE);</span><br><span class="line">	mul_Q31[i] = hamming_window_Q16[i] * input_Q15[i];</span><br><span class="line">&#125;</span><br><span class="line">arm_cfft_q31(&amp;arm_cfft_sR_q31_len32, mul_Q31, <span class="number">0</span>, <span class="number">1</span>);</span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">32</span>; i++)</span><br><span class="line">&#123;</span><br><span class="line">       <span class="built_in">printf</span>(<span class="string">&quot;%4d: %.8f, %.8f\r\n&quot;</span>, i, mul_Q31[<span class="number">2</span>*i]/<span class="number">67108864.0</span> , mul_Q31[<span class="number">2</span>*i+<span class="number">1</span>]/<span class="number">67108864.0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    对比两者运算的结果，误差基本很小：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152339.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408152608.png" style="zoom:40%;">

<p>​    下面对C中的代码做简单介绍：</p>
<ul>
<li><p>代码中汉明窗的值固定小于1的,<strong>并且固定是正数</strong>，所以直接转换成Q16的值，注意转换后的值要是uint16_t类型，不然有可能放不下原来的数据。（因为int16_t的范围是-32768~32767）</p>
</li>
<li><p>做完fft之后的结果对一致性的时候需要除以67108864(即2的26次方)，原因如下所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153251.png" style="zoom:87%;">

</li>
</ul>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408153427.png" style="zoom:80%;">

<p>​    当做32点FFT的时候，输入格式为1.31，输出格式应该为6.26，即输出为Q26的数据。</p>
<p>​    <strong>情形二</strong>：当输入的数据不是(-1, 1)之间的值，而是int16_t类型的值时，怎么处理？我们这边可以把它当成是Q15的值，最终和python那端对一致性的时候，把C工程中输出结果也转成Q15的。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408161947.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162118.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162242.png" style="zoom:80%;">

<p>最终对比两者运算的结果：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162426.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210408162514.png" style="zoom:47%;">

<p>​    这边除以2048(即2的11次方)的原因是，32点FFT输出的是Q26格式，但是最终和python对一致性的是用Q15格式，所以需要除以2的11次方。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/" class="post-title-link" itemprop="url">STM32使用RTC时钟及闹钟功能</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-05 22:17:05" itemprop="dateCreated datePublished" datetime="2021-04-05T22:17:05+08:00">2021-04-05</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/" class="post-meta-item leancloud_visitors" data-flag-title="STM32使用RTC时钟及闹钟功能" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/05/STM32%E4%BD%BF%E7%94%A8RTC%E6%97%B6%E9%92%9F%E5%8F%8A%E9%97%B9%E9%92%9F%E5%8A%9F%E8%83%BD/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    这里在STM32L475VET6芯片上实现RTC时钟获取，并且实现周期性闹钟提醒，这个闹钟提醒还是很有用的，比如在做低功耗的时候，你可以用RTC闹钟提醒事件的中断唤醒处于低功耗模式的mcu，mcu做完自己的事情再进入低功耗，这样周期往复执行实现低功耗。</p>
<h2 id="1-cubemx配置工程"><a href="#1-cubemx配置工程" class="headerlink" title="1. cubemx配置工程"></a>1. cubemx配置工程</h2><p>​    我用的板子是正点原子的潘多拉开发板，板子上用的是外部的32.768K晶振供RTC，我们先配置主时钟和RTC时钟。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405194928.png" style="zoom:50%;">

<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405195402.png" style="zoom:80%;">    配置RTC时钟，激活日历和时钟源，这里我设置时间为2021年4月5日20点0分0秒，设置闹钟提醒的时间为4s:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405200631.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405200633.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405200636.png" style="zoom:67%;">

<p>​    上述闹钟在每次匹配到秒为4的时候激活闹钟中断（也就是一分钟激活一次中断，忽略对日期、小时、分钟和Sub秒的匹配）。</p>
<p>​    使能RTC闹钟提醒功能的中断:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405201105.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405201555.png" style="zoom:50%;">

<h2 id="2-编写代码"><a href="#2-编写代码" class="headerlink" title="2. 编写代码"></a>2. 编写代码</h2><p>​    HAL库获取RTC时间的函数有两个：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">HAL_RTC_GetTime：获取时间</span><br><span class="line">HAL_RTC_GetDate：获取日期</span><br><span class="line">必须先调用HAL_RTC_GetTime,然后再调用HAL_RTC_GetDate</span><br></pre></td></tr></table></figure>
<p>​    这两个函数的第三个参数是格式：RTC_FORMAT_BIN和RTC_FORMAT_BCD，BIN格式就是十六进制数值直接表示的时间数值，BCD格式就是用数值的十六进制面值表示时间数值，例如表示第24分钟的时候，BCD格式的分钟值就是0X24。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> pack(1)</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">uint8_t</span> Hours;</span><br><span class="line">    <span class="keyword">uint8_t</span> Minutes;</span><br><span class="line">    <span class="keyword">uint8_t</span> Seconds;</span><br><span class="line">    <span class="keyword">uint8_t</span> WeekDay;</span><br><span class="line">    <span class="keyword">uint8_t</span> Month;</span><br><span class="line">    <span class="keyword">uint8_t</span> Day;</span><br><span class="line">    <span class="keyword">uint8_t</span> Year;</span><br><span class="line">&#125; <span class="keyword">rtc_time_t</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> pack()</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">RTC_GetTime</span><span class="params">(<span class="keyword">rtc_time_t</span>* time)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    HAL_RTC_GetTime(&amp;hrtc, (RTC_TimeTypeDef *)&amp;time-&gt;Hours,   RTC_FORMAT_BIN);</span><br><span class="line">    HAL_RTC_GetDate(&amp;hrtc, (RTC_DateTypeDef *)&amp;time-&gt;WeekDay, RTC_FORMAT_BIN);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    编写闹钟时间回调函数，HAL库中这个回调函数是__weak类型，需要用户自己来填写，我们就在产生回调的时候打印此刻的时间。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405221137.png"></p>
<h2 id="3-运行效果"><a href="#3-运行效果" class="headerlink" title="3. 运行效果"></a>3. 运行效果</h2><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405221650.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/05/%E7%94%A8CubeMx%E7%94%9F%E6%88%90stm32mp157%E7%9A%84MDK%E5%B7%A5%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/05/%E7%94%A8CubeMx%E7%94%9F%E6%88%90stm32mp157%E7%9A%84MDK%E5%B7%A5%E7%A8%8B/" class="post-title-link" itemprop="url">用CubeMx生成stm32mp157的MDK工程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-05 19:23:19" itemprop="dateCreated datePublished" datetime="2021-04-05T19:23:19+08:00">2021-04-05</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/05/%E7%94%A8CubeMx%E7%94%9F%E6%88%90stm32mp157%E7%9A%84MDK%E5%B7%A5%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="用CubeMx生成stm32mp157的MDK工程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/05/%E7%94%A8CubeMx%E7%94%9F%E6%88%90stm32mp157%E7%9A%84MDK%E5%B7%A5%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/05/%E7%94%A8CubeMx%E7%94%9F%E6%88%90stm32mp157%E7%9A%84MDK%E5%B7%A5%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    第一次尝鲜stm32mp157这款多核异构的芯片，这里记录一下使用CubeMX来生成M4内核的MDK工程过程。</p>
<h2 id="1-下载使用stm32cube固件包"><a href="#1-下载使用stm32cube固件包" class="headerlink" title="1.下载使用stm32cube固件包"></a>1.下载使用stm32cube固件包</h2><p>​    点击 Help-&gt;Manage embedded software packages，在该窗口找到 STM32MP1 列表选项，勾选 1.3.0 版本，并点击Install Now，软件会在线下载好固件包并解压，会自动关联好。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210330201526.png" style="zoom:40%;">

<h2 id="2-工程建立"><a href="#2-工程建立" class="headerlink" title="2. 工程建立"></a>2. 工程建立</h2><h3 id="2-1-初步建立工程"><a href="#2-1-初步建立工程" class="headerlink" title="2.1 初步建立工程"></a>2.1 初步建立工程</h3><p>​    点击 ACCESS TO MCU SELECTOR，我手边的板子是百问网的100ASK_STM32MP157_V11开发板，板子上的mcu型号是stm32mp157DAC1，双击选中芯片型号后，弹出主设计界面。</p>
<h3 id="2-2-HSE时钟源设置"><a href="#2-2-HSE时钟源设置" class="headerlink" title="2.2 HSE时钟源设置"></a>2.2 HSE时钟源设置</h3><p>​    STM32MP157的M4，拥有五个时钟源：</p>
<ul>
<li><p>HSI(High-speed internal oscillator)：</p>
<p>HIS 是内部的高速 RC 振荡器，频率 64MHz。因为是内部提供，可以降低成本，缺点是精度较差。</p>
</li>
<li><p>HSE(High-speed external oscillator):</p>
<p>HSE 是外部的高速振荡器，需要外部电路晶振，输入频率范围要求为 4-48MHz。因为需要外部电路提供，成本会增加，但精度较好。</p>
</li>
<li><p>LSI(Low-speed internal oscillator)：</p>
<p>LSI 是内部的低速 RC 振荡器，频率 32KHz。一般用于看门狗、RTC 实时时钟、DAC 等。</p>
</li>
<li><p>LSE(Low-speed external oscillator):</p>
<p>LSE 是外部的低速振荡器，需要外部电路晶振，输入频率范围要求为 0-1000KHz，常使用 32.768KHz。一般用于 RTC 实时时钟。</p>
</li>
<li><p>CSI(Low-power internal oscillator):</p>
<p>CSI 是内部的低功耗 RC 振荡器，频率 4MHz。主要用于低功耗，需要低功耗时代替 64MHz 的 HSI。</p>
<p>我们这里选择使用HSE作为时钟源，如下图所示。</p>
</li>
</ul>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210330210221.png" style="zoom:40%;">

<p>HSE我们选择了Crystal/Ceramic Resonator，表示选择外部晶振作为它们的时钟源。我们开发板的外部高速晶振（HSE）是：24MHZ。</p>
<h3 id="2-3-时钟树配置"><a href="#2-3-时钟树配置" class="headerlink" title="2.3 时钟树配置"></a>2.3 时钟树配置</h3><p>​    打开时钟树配置图，可以看到MCU的时钟默认使用的是64MHz 的HSI，如下图所示：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210330204418.png"></p>
<p>我们这边改成使用HSE，并将最后的MCU系统时钟设置到209MHz，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210330205618.png" style="zoom:80%;">

<h3 id="2-4-生成工程源码"><a href="#2-4-生成工程源码" class="headerlink" title="2.4 生成工程源码"></a>2.4 生成工程源码</h3><p>​    进入Project Manager-&gt;Project 选项来配置工程，其他地方可以不改。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210330211912.png" style="zoom:40%;">

<p>​    再打开Project Manager-&gt;Code Generator选项，勾选 Generate </p>
<p>peripheral initialization as a pair of .c/.h‘files per peripheral，勾选这个选项的话将会将每个外设单独生成一组.c和.h 文件，这使得代码结构更加的清晰。</p>
<p>​    到这工程基本算配置好了，再点击蓝色按钮(GENERATE CODE)就可以生成工程。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331210355.png" style="zoom:50%;">

<p>​    这里挑几个文件夹，简单介绍一下。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210401193628.png"></p>
<h2 id="3-测试"><a href="#3-测试" class="headerlink" title="3. 测试"></a>3. 测试</h2><p>​    为了测试工程，我们这边调用HAL_RCC_GetSystemCoreClockFreq()，获取设置后的新系统时钟，看是否是我们设置的209MHz。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="comment">/* USER CODE BEGIN 1 */</span></span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">uint32_t</span> sys_freq = <span class="number">0</span>; </span><br><span class="line">  <span class="comment">/* USER CODE END 1 */</span></span><br><span class="line">  <span class="comment">/* MCU Configuration-------------------------------------------------*/</span></span><br><span class="line">  <span class="comment">/* Reset of all peripherals, Initializes the Flash interface and the Systick. */</span></span><br><span class="line">  HAL_Init();</span><br><span class="line"></span><br><span class="line">  <span class="comment">/* USER CODE BEGIN Init */</span></span><br><span class="line">  <span class="comment">/* USER CODE END Init */</span></span><br><span class="line">  <span class="keyword">if</span>(IS_ENGINEERING_BOOT_MODE())</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="comment">/* Configure the system clock */</span></span><br><span class="line">    SystemClock_Config();</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/* USER CODE BEGIN SysInit */</span></span><br><span class="line">  <span class="comment">/* USER CODE END SysInit */</span></span><br><span class="line">  <span class="comment">/* Initialize all configured peripherals */</span></span><br><span class="line">  MX_GPIO_Init();</span><br><span class="line">  <span class="comment">/* USER CODE BEGIN 2 */</span></span><br><span class="line">  sys_freq = HAL_RCC_GetSystemCoreClockFreq();</span><br><span class="line">  <span class="comment">/* USER CODE END 2 */</span></span><br><span class="line">  <span class="comment">/* Infinite loop */</span></span><br><span class="line">  <span class="comment">/* USER CODE BEGIN WHILE */</span></span><br><span class="line">  <span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="comment">/* USER CODE END WHILE */</span></span><br><span class="line">    <span class="comment">/* USER CODE BEGIN 3 */</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/* USER CODE END 3 */</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="4-用ST-LINK下载和仿真调试程序"><a href="#4-用ST-LINK下载和仿真调试程序" class="headerlink" title="4. 用ST LINK下载和仿真调试程序"></a>4. 用ST LINK下载和仿真调试程序</h2><p>​    将BOOT设置为001,设置为M4内核启动。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405180100.jpg" style="zoom:20%;">

<p>​    在keil中设置我们的仿真器：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405180507.png" style="zoom:33%;">

<p>​    接下来还需要在 Utilities 选项卡里面设置下载时的目标编程器：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405180851.png" style="zoom:50%;">

<p>​    勾选“Use Debug Driver”，选择 ST LINK 来调试、下载。“Update Target before Debuggin”顾名思义，就是在调试之前先将代码下载到目标器件中，由于 STM32MP157 M4 没有内部 Flash，因此绝对不能勾选此选项！否则仿真就会失败，对于那些内置 Flash 的 STM32 单片机需要勾选此选项。</p>
<p>​    点击开始/停止仿真按钮，直接报错了。。。。。如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405184915.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405184917.png" style="zoom:50%;">

<p>​    查阅网上资料，发现有网友有遇到过同样的问题，按照他的方法可以解决这个问题：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405191843.png" style="zoom:47%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210405192213.png" style="zoom:67%;">

<p>sys_freq的值为209000128，说明我们工程没有问题。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/01/cmake%E5%B9%B6%E8%A1%8C%E6%89%A7%E8%A1%8C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/01/cmake%E5%B9%B6%E8%A1%8C%E6%89%A7%E8%A1%8C/" class="post-title-link" itemprop="url">cmake并行执行</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-01 10:25:22" itemprop="dateCreated datePublished" datetime="2021-04-01T10:25:22+08:00">2021-04-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/04/01/cmake%E5%B9%B6%E8%A1%8C%E6%89%A7%E8%A1%8C/" class="post-meta-item leancloud_visitors" data-flag-title="cmake并行执行" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/04/01/cmake%E5%B9%B6%E8%A1%8C%E6%89%A7%E8%A1%8C/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/04/01/cmake%E5%B9%B6%E8%A1%8C%E6%89%A7%E8%A1%8C/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/I23mage.png" style="zoom:70%;">

<p>​    执行这两个目标，如果只执行make，不会并行执行，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imag33e.png" style="zoom:80%;">

<p>​    执行make -j2才会并行执行，造成错乱：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Im67age.png" style="zoom:80%;">



<p>​    网上有个例子如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Im15age.png" style="zoom:80%;">

<p>​     If you generate a Makefile from this and run make -j 2, you’ll see the following:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image44.png" style="zoom:80%;">

<p>​    If creating ‘gen’ takes a long time, then you really don’t want it to happen multiple times! It may even cause disasters, for example running make twice at once in the same Buildroot build tree is not pretty at all.</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Ima88ge.png" style="zoom:67%;">

<p>​    这样的问题是会编两次gen，用户等的时间就长了。the solution is (guess what!) to wrap the custom command in a custom target!</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Ima88ge.png" style="zoom:67%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/03/31/MM32%20eMiniBoard%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/03/31/MM32%20eMiniBoard%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="post-title-link" itemprop="url">MM32 eMiniBoard环境搭建</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-31 20:45:04" itemprop="dateCreated datePublished" datetime="2021-03-31T20:45:04+08:00">2021-03-31</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/03/31/MM32%20eMiniBoard%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="post-meta-item leancloud_visitors" data-flag-title="MM32 eMiniBoard环境搭建" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/03/31/MM32%20eMiniBoard%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/03/31/MM32%20eMiniBoard%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    最近手头拿到了一块灵动微的eMiniBoard MB-025开发板，主芯片是MM32F0133C7P。啥话都不说，我们先把开发环境搭建一下。</p>
<p>​    灵动微的板子可以用keil开发，先去它的官网下载安装Keil pack包。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331202029.png" style="zoom:48%;">

<p>​    然后是MM32-LINK，板载的下载调试器，本身就是个CMSIS-DAP的一个马甲。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331202256.jpg" style="zoom:67%;">

<p>​    左上角是MM32-LINK的下载调试接口，下方一个是主芯片的USB接口，当要使用芯片的USB功能时，接此接口。为了能够在keil上使用mm32-link来下载调试程序，需要安装mm32_devkit_setup，它是MM32-Link编程开发与调试安装包，包含MM32-Link KEIL Debugger驱动组件、MM32-Link IAR Debugger驱动组件、MM32Program PC端软件与使用说明。安装过程会出现如下界面：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331202855.png" style="zoom:60%;">

<p>如果电脑上已经安装了KEIL软件会自动识别出安装的KEIL目录。安装结束后可以在自己的KEIL安装目录Keil_v5\ARM\BIN下可以看到MM32LINKCM3.dll文件。只有安装好这个之后才能在keil的Debug下看到MM32-LINK Debugger，之后就可以尽情下载调试了。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331204002.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210331204004.png" style="zoom:50%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/24/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/24/">24</a><span class="page-number current">25</span><a class="page-number" href="/page/26/">26</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/26/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
